from moviepy.editor import VideoFileClip, concatenate_videoclips


def video_to_gif(input_video, start_time, end_time, output_gif):
    clip = VideoFileClip(input_video).subclip(start_time, end_time)
    clip.write_gif(output_gif, fps=10)


input_video = "C:\\Users\\asus\\Downloads\\oceans.mp4"  # 输入视频文件名
start_time = 10  # 开始时间（秒）
end_time = 20  # 结束时间（秒）
output_gif = "C:\\Users\\asus\\Desktop\\709\\file\\output.gif"  # 输出GIF文件名

video_to_gif(input_video, start_time, end_time, output_gif)
